extern crate serde;
extern crate serde_json;

use serde::{Serialize, Deserialize};
use std::fmt::{self, Formatter, Display};

#[derive(Serialize, Deserialize, Debug)]
pub struct Banner{
    pub item_desc:String,
    pub id:i32,
    pub image_path:String,
    pub is_visible:i32,
    pub item_order:i32,
    pub title:String,
    pub item_type:i32,
    pub url:String,
    pub deleted:bool,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BannersData{
    pub data:Option<Vec<Banner>>,
    pub error_code:i32,
    pub error_msg:String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BannerData{
    pub data:Option<Banner>,
    pub error_code:i32,
    pub error_msg:String,
}
impl Display for Banner {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        write!(f, "{}:{}:{}:{}:{}:{}:{}:{}:{}",self.item_desc, self.id, self.image_path,self.is_visible, self.item_order,
               self.title,self.item_type, self.url, self.deleted)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_display() {
        let n = Banner{
            item_desc:String::from("doc"),
            id:111,
            image_path:String::from("google.com"),
            is_visible:1,
            item_order:1,
            title:String::from("google.com"),
            item_type:1,
            url:String::from("google.com"),
            deleted:false,
        };
        println!("{}",n);
    }

}